<?php

namespace app\admin\controller;

use app\common\controller\AdminBase;
use app\common\model\QuestionType;
class Grade extends AdminBase
{
    protected function _initialize()
    {
        parent::_initialize();
    }
    /**
     * 年级列表
     */
    public function index()
    {
        $list=model('grade')->where('status',['>',0])->paginate(config('page_number'));
        return $this->fetch('index', ['grade' =>$list]);
    }
    /**
     * 添加年级
     */
    public function add(){
        $param = $this->request->param();
        if ($this->request->isPost()) {
            if($this->insert('grade', $param) === true){
                insert_admin_log('添加年级');
                $this->success('添加年级成功', url('admin/grade/index'));
            }else{
                $this->error($this->errorMsg);
            }
        }
        if(isset($param['id'])){
            $param=model('grade')->where('status',['>',0])->where('id',$param['id'])->paginate(config('page_number'));
        }
        $list=model('grade')->where('status',['>',0])->paginate(config('page_number'));
        return $this->fetch('addgrade', ['data' =>$param,'grade' =>$list]);
    }
    /**
     * 编辑职位
     */
    public function edit()
    {
        $param = $this->request->param();
        if ($this->request->isPost()) {
            if ($this->update('grade', $param, input('_verify', true)) === true) {
                insert_admin_log('修改了职位');
                $this->success('修改职位成功', url('admin/grade/index'));
            } else {
                $this->error($this->errorMsg);
            }
        }
        return $this->fetch('addgrade', ['data' => model('grade')->where('id', input('id'))->find()]);
    }
    /**
     * 删除年级
     */
    public function del()
    {
        if ($this->request->isGet()) {
            $param = $this->request->param();
            if ($this->delete('grade', $param ) === true) {
                insert_admin_log('删除了职位');
                $this->success('职位删除成功', url('admin/grade/index'));
            } else {
                $this->error($this->errorMsg);
            }
        }
    }


    /**
     * 年级状态设置
     */
    public function teacherstatus(){
        if ($this->request->isPost()) {
            $param = $this->request->param();
            if($this->update('grade', ['id'=>$param['id'],'status'=>$param['status']], input('_verify', true)) and $this->update('integral', ['id'=>$param['id'],'status'=>$param['status']], input('_verify', true),$field = true )){
               $this->success('操作成功！', url('admin/grade/index'));
            } else{
               $this->error($this->errorMsg);
            }
            $this->success('操作成功', url('admin/grade/index'));
        }
    }
    /**
     * 开发商状态设置
     */
    public function dev(){
        if ($this->request->isPost()) {
            $param = $this->request->param();
            if($this->update('grade', ['id'=>$param['id'],'status'=>$param['dev']], input('_verify', true)) and $this->update('integral', ['id'=>$param['id'],'status'=>$param['dev']], input('_verify', true),$field = true )){
                $this->success('操作成功！', url('admin/grade/index'));
            } else{
                $this->error($this->errorMsg);
            }
            $this->success('操作成功', url('admin/grade/index'));
        }
    }


}
